/**
 * Copyright (C), 2015-2024, XXX有限公司
 * FileName: InsertSort
 * Author:   Administrator
 * Date:     2024/3/23 17:50
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */

/**
 * 〈一句话功能简述〉<br>
 * 〈〉
 *
 * @author Administrator
 * @create 2024/3/23
 * @since 1.0.0
 */
public class InsertSort {

    public static void main(String[] args) {
        int[] arrays = {8, 6, 1, 7, 2, 5, 4, 12, 9, 3};

        for (int i = 1; i < arrays.length; i++) {
            int start = i;
            int insert = arrays[start];
            while (start > 0) {
                if (arrays[start - 1] > insert) {
                    arrays[start] = arrays[start - 1];
                } else {
                    arrays[start] = insert;
                    break;
                }
                start--;
            }

            if (start == 0) {
                arrays[0] = insert;
            }
        }


        for (int i = 0; i < arrays.length; i++) {
            System.out.print(arrays[i] + " ");
        }
    }
}